#pragma once
#include <map>
#include <vector>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <memory>
#include "PurchaseRedemptionList.hpp"

namespace StockMarket
{
    class Stock;
    class ETF
    {
    private:
        int m_security_id;
        long long m_total_price = 3869220000;// 预估现金差（申购赎回清单）
        const long long m_total_quality = 1000000;// 最小申购、赎回单位 （申购赎回清单）

        std::unordered_set<int> m_updated_stocks; // 记录那些已经更新过了的股票的价格

        // {股票编号，持有量}（单位手）
        std::unordered_map<int, int> m_quality;

        std::unordered_map<int, PurchaseRedemptionEntry> m_stocks;
        std::unordered_map<int, std::weak_ptr<Stock>> m_stock_ptr;

        std::map<int, int> m_stock_price;

    public:
        ETF() = delete;
        explicit ETF(int security_id) : m_security_id(security_id) {}
        ~ETF() {}
        void addStock(int code, std::weak_ptr<Stock> stock);
        void addStock(const std::vector<PurchaseRedemptionEntry> &list);
        void updateIOPV(int stock, int old_price, int new_price);
        long long getIOPV() const;
        inline long long divideAndRound(long long numerator, long long denominator) const
        {
            return (numerator + denominator / 2) / denominator;
        }
        inline int getSecurityId() const
        {
            return m_security_id;
        }
        inline std::map<int, int> getAllStockPrice() const
        {
            return m_stock_price;
        }
        inline std::unordered_map<int, int> getAllStockQuality() const
        {
            return m_quality;
        }
    };
} // namespace StockMarket
